﻿<html>
	<head>
		<title>测试页</title>
		<style type="text/css">
			.container {
				background-image: url("images/transparent_test.png");
				width:100px;
				height:100px;
				border: 1px solid gray;
			}
		</style>
		<script type="text/javascript">
			//使background形式png透明——单个
			function testTranseparent(id) {
				var rslt = navigator.appVersion.match(/MSIE (\d+.\d+)/, '');
				var itsGood = (rslt != null && Number(rslt[1]) > 6.0);
				if(!itsGood) {
					if(typeof id == "string") {
						var container = document.getElementById(id);
						var bg = container.currentStyle.backgroundImage;
						if(bg) {
							if (bg.match(/.png/i) != null) {
								var mypng = bg.substring(5, bg.length-2);
								container.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + mypng + "', sizingMethod='crop')";
								container.style.backgroundImage = "url('')";
							}
						}
					}
				}
			}
			
			//使background形式png透明——批量
			function alphaPNGBackgrounds() {
				var rslt = navigator.appVersion.match(/MSIE (\d+.\d+)/, '');
				var itsAllGood = (rslt != null && Number(rslt[1]) > 6.0);
				if(!itsAllGood) {
					for(i = 0; i < document.all.length; i++) {
						var bg = document.all[i].currentStyle.backgroundImage;
						if(bg) {
							if (bg.match(/.png/i) != null) {
								var mypng = bg.substring(5, bg.length-2);
								document.all[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + mypng + "', sizingMethod='crop')";
								document.all[i].style.backgroundImage = "url('')";
							}
						}
					}
				}
			}
			
			//使<img>形式的png透明，未经测试
			function correctPNG() {
				for(var i = 0; i < document.images.length; i++) {
					var img = docuemnt.images[i];
					var imageName = img.src.toUpperCase();
					if(imgName.substring(imgName.length - 3, imaName.length) == "PNG") {
						var imgID = (img.id) ? "id='" + img.id + "' " : "";
						var imgClass = (img.className) ? "class='" + img.title + "' " : "";
						var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
						var imgStyle = "display:inline-block;" + img.style.cssText;
						if (img.align == "left")
							imgStyle = "float:left;" + imgStyle;
						if (img.align == "right")
							imgStyle = "float:right;" + imgStyle;
						if (img.parentElement.href) {
							imgStyle = "cursor:hand;" + imgStyle;
						}
						var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
						img.outerHTML = strNewHTML;
						i = i - 1;
					}
				}
			}
			
			function test() {
				testTranseparent("testDiv");
			}
		</script>
	</head>
	<body onload="pngAll()">
		<div id="testDiv" class="container"></div>
	</body>
</html>